<?php
class BlogCategoriesController extends AppController {

	var $name = 'BlogCategories';

        function beforeFilter(){
		parent::beforeFilter();
	  	$this->Auth->allowedActions = array('view','index');

	}

	function index() {
		$this->BlogCategory->recursive = 0;
		$this->set('blogCategories', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid blog category', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('blogCategory', $this->BlogCategory->read(null, $id));
	}

	function add() {
            $this->layout=null;
		if (!empty($this->data)) {
			$this->BlogCategory->create();
			if ($this->BlogCategory->save($this->data)) {
				$this->Session->setFlash(__('The blog category has been saved', true));
				//$this->redirect(array('action' => 'index'));
                                $this->render('success');
			} else {
				$this->Session->setFlash(__('The blog category could not be saved. Please, try again.', true));
                                $this->render('success');
			}
		}
	}

	function edit($id = null) {
            $this->layout=null;
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid blog category', true));
			$this->render('success');
		}
		if (!empty($this->data)) {
			if ($this->BlogCategory->save($this->data)) {
				$this->Session->setFlash(__('The blog category has been saved', true));
			        $this->render('success');
			} else {
				$this->Session->setFlash(__('The blog category could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->BlogCategory->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for blog category', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->BlogCategory->delete($id)) {
			$this->Session->setFlash(__('Blog category deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Blog category was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
	function backstage_index() {
            $this->layout='admin';
		$this->BlogCategory->recursive = 0;
		$this->set('blogCategories', $this->paginate());
	}

	function backstage_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid blog category', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('blogCategory', $this->BlogCategory->read(null, $id));
	}

	function backstage_add() {
		if (!empty($this->data)) {
			$this->BlogCategory->create();
			if ($this->BlogCategory->save($this->data)) {
				$this->Session->setFlash(__('The blog category has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The blog category could not be saved. Please, try again.', true));
			}
		}
	}

	function backstage_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid blog category', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->BlogCategory->save($this->data)) {
				$this->Session->setFlash(__('The blog category has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The blog category could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->BlogCategory->read(null, $id);
		}
	}

	function backstage_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for blog category', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->BlogCategory->delete($id)) {
			$this->Session->setFlash(__('Blog category deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Blog category was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>